#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
using namespace std;
class Solution
{
public:
    string str, ans;
    void dfs(int index, int m, string &str, int k, int &cnt)
    {
        if (cnt > k)
            return;
        if (index == m)
        {
            if (cnt == k)
                ans = str;
            cout << cnt << ": " << str << endl;
            cnt++;
        }
        else
        {
            string tmp = str;
            for (int i = index; i <= m; ++i)
            {
                int ii = i;
                while (ii > index)
                {
                    swap(str[ii], str[ii - 1]);
                    ii--;
                }
                dfs(index + 1, m, str, k, cnt);
                str = tmp;
            }
        }
    }
    string getPermutation(int n, int k)
    {
        int cnt = 1;
        for (int i = 1; i <= n; ++i)
        {
            str.push_back(i + '0');
        }
        dfs(0, n - 1, str, k, cnt);
        return ans;
    }
};
int main()
{
    Solution slover;
    slover.getPermutation(3, 5);
    cout << slover.ans << endl;
    return 0;
}